<template>
  <div class="page-container">
    <el-card shadow="never" class="search-form-card">
      <el-form class="search-form" inline label-width="75px" label-suffix=":">
        <el-row :gutter="50">
          <el-col :span="8">
            <el-form-item label="提交部门">
              <ElSelectTree
                v-model="searchParams.deptId"
                :data="deptList"
                node-key="id"
                :props="{
                  label: 'deptName',
                  children: 'children'
                }"
                check-strictly
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="审核状态">
              <el-select v-model="searchParams.status" placeholder="请选择">
                <el-option
                  v-for="item in statusList"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="提交审核时间" label-width="120px">
              <el-date-picker
                v-model="searchParams.timeValue"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="工具名称">
              <el-input v-model="searchParams.name" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <el-button type="primary" @click="onSearch">查询</el-button>
              <el-button @click="onReset">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <el-card shadow="never">
      <el-tabs v-model="activeName">
        <el-tab-pane label="发布审核" name="publish">
          <publish-page ref="publish" :params="searchParams" />
        </el-tab-pane>
        <el-tab-pane label="订阅审核" name="subscribe">
          <sub-page ref="subscribe" :params="searchParams" />
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import PublishPage from './publishPage'
import SubPage from './subPage'
import { mapGetters } from 'vuex'
import { http_dept } from '@/api'

export default {
  components: {
    PublishPage,
    SubPage
  },
  computed: {
    ...mapGetters(['enum']),
    statusList() {
      return this.enum['AuditDataStatusType'] || []
    }
  },
  data() {
    return {
      activeName: 'publish',
      searchParams: {
        timeValue: [],
        status: '',
        deptId: '',
        name: ''
      },
      deptList: []
    }
  },
  created() {
    http_dept.tree().then(res => {
      this.deptList = res
    })
  },
  methods: {
    onSearch() {
      this.$refs[this.activeName].onSearch()
    },
    onReset() {
      for (const key in this.searchParams) {
        switch (key) {
          case 'timeValue':
            this.searchParams.timeValue = []
            break
          default:
            this.searchParams[key] = ''
        }
      }
      this.onSearch()
    }
  }
}
</script>

<style lang="scss" scoped>
.page-container {
  height: 100%;
}
</style>
